package com.wootion.dizhi.service.impl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wootion.dizhi.comon.StringUtil;
import com.wootion.dizhi.dao.MethodEnumerationDao;
import com.wootion.dizhi.entity.MethodEnumeration;
import com.wootion.dizhi.response.Result;
import com.wootion.dizhi.service.ResourceEstimationService;
import com.wootion.dizhi.vo.Condition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@Service
public class ResourceEstimationServiceImpl implements ResourceEstimationService {
    @Resource
    private MethodEnumerationDao methodEnumerationDao;
    /**
     * 添加方法列举选用
     * @return
     */
    @Override
    public Result insert(MethodEnumeration methodEnumeration) {
        methodEnumeration.setCreateTime(new Date());
        methodEnumeration.setCreateDate(new Date());
        int rows = methodEnumerationDao.insert(methodEnumeration);
        return rows > 0 ?Result.success():Result.error("添加失败");
    }

    /**
     * 通过计算得出资源量数据
     * @param condition
     * @return
     */
    @Override
    public Result list(Condition condition) {
        Page<MethodEnumeration> page = new Page<>(condition.getPageNo(),condition.getPageSize());
        Page<MethodEnumeration> methodEnumerationPage = methodEnumerationDao.list(page, condition);
        return Result.success(methodEnumerationPage);
    }
    /**
     * 根据id查询
     * @return
     */
    @Override
    public Result findById(String id) {
        MethodEnumeration methodEnumeration = methodEnumerationDao.selectById(id);
        return Result.success(methodEnumeration);
    }
    /**
     * 根据id删除
     * @return
     */
    @Override
    public Result deleteById(String id) {
        int rows = methodEnumerationDao.deleteById(id);
        return rows > 0 ? Result.success() : Result.error("删除失败");
    }
    /**
     * 更新方法列举选用
     * @return
     */
    @Override
    public Result update(MethodEnumeration methodEnumeration) {
        methodEnumeration.setUpdateTime(new Date());
        int rows = methodEnumerationDao.updateById(methodEnumeration);
        return rows > 0 ? Result.success() : Result.error("更新失败");
    }
}
